package com.integrance.budgetapp.domain;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "INCOME")
public class Income {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "income_id", nullable = false, unique = true)
	private Long id;

	@ManyToOne(optional = false)
	@JoinColumn(name = "income_source_id", nullable = false)
	private IncomeSource incomeSource;

	@Column(name = "amount", precision = 2) // TODO use precision or scale?
	private BigDecimal amount;

	@Column(name = "label", length = 30, nullable = false)
	private String label;

	@Column(name = "income_timestamp")
	private Date timestamp;

	@ManyToMany(mappedBy = "incomes")	
	private Set<Budget> budgets;		
	
	public Income() {
	}

	public Income(String label, IncomeSource incomeSource) {
		this.label = label;
		this.incomeSource = incomeSource;
	}

	public BigDecimal getAmount() {
		return amount;
	}

	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}

	public Long getId() {
		return id;
	}

	private void setId(Long id) {
		this.id = id;
	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public IncomeSource getIncomeSource() {
		return incomeSource;
	}

	public void setIncomeSource(IncomeSource source) {
		this.incomeSource = source;
	}

	public Date getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(Date timestamp) {
		this.timestamp = timestamp;
	}
	
	public Set<Budget> getBudgets() {
		return budgets;
	}
	
	public void setBudgets(Set<Budget> budgets) {
		this.budgets = budgets;
	}
}
